//
//  GHOrderFooterView.m
//  GodHorses
//
//  Created by Mac on 2017/11/20.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "KLOrderFooterView.h"
@interface KLOrderFooterView()
@property(nonatomic, strong) STLabel                     *payLable;//应付款
@property(nonatomic, strong) STLabel                     *timeLable;//应付款
@property(nonatomic, strong) STLabel                     *orderLable;//应付款
@end
@implementation KLOrderFooterView

+ (CGFloat)footerHeight{
    return 160 + 10 + 30;
}
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithReuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, [KLOrderFooterView footerHeight] - 10)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:whiteView];
    
    self.payLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 40)
                                              text:@"共两件商品,应付款 3600"
                                         textColor:KL_redColor
                                              font:14
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.payLable];
    
    self.timeLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.payLable.st_bottom, UIScreenWidth - 20, 40)
                                              text:@"可用余额：20：00"
                                         textColor:KL_firstTextColor
                                              font:14
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.timeLable];
    
    self.orderLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.timeLable.st_bottom, UIScreenWidth - 20, 40)
                                                 text:@"可用积分：100"
                                            textColor:KL_firstTextColor
                                                 font:14
                                          isSizetoFit:NO
                                        textAlignment:NSTextAlignmentRight];
    [whiteView addSubview:self.orderLable];
    

    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(10, self.orderLable.bottom , UIScreenWidth - 20, 0.5)];
    line.backgroundColor = KL_lineColor;
    [whiteView addSubview:line];


    
    self.menuButton = [[STButton alloc] initWithFrame:CGRectMake(0, line.bottom  +20, 65, 30)
                                                  title:@"取消订单"
                                             titleColor:KL_YellowBackGroundColor
                                              titleFont:13
                                           cornerRadius:8
                                        backgroundColor:[UIColor whiteColor]
                                        backgroundImage:nil
                                                  image:nil];
    self.menuButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.menuButton.st_right = UIScreenWidth - 15  ;
    [self.menuButton st_setBorderWith:1 borderColor:KL_YellowBackGroundColor cornerRadius:8];
    [whiteView addSubview:self.menuButton];
    
}
- (NSString*)defultTitle{
    NSLog(@"订单状态%@",_model.order_status);
    switch (_model.order_status.integerValue) {
        case 0:
            return @"付款";
            break;
        case 1:
            return @"";
            break;
        case 2:
            return @"确认收货";
            break;
        case 3:
            return @"评价";
            break;
        case 9:
            return @"再次评价";
            break;
        default:
            break;
    }
    return @"";
}
- (NSString*)defultShopTitle{
    NSLog(@"订单状态%@",_model.order_status);
    switch (_model.order_status.integerValue) {
        case 0:
            return @"发货";
            break;
        case 1:
            return @"发货";
            break;
        case 2:
            return @"";
            break;
        case 3:
            return @"";
            break;
        case 9:
            return @"已完成";
            break;
        default:
            break;
    }
    return @"";
}
- (void)setModel:(KLOrderModel *)model{
    _model = model;
    NSString * title = [self defultTitle];
    [self.menuButton setTitle:title forState:UIControlStateNormal];
    self.menuButton.hidden = !self.menuButton.currentTitle.length;
    
    NSInteger num = 0;
    CGFloat price = 0;
    for (KLOrderGoodModel * good in model.goodsorder) {
        num = num + good.goods_num.integerValue;
        price = price + good.goods_num.integerValue * good.goods_price.floatValue;
    }
    self.payLable.text = [NSString stringWithFormat:@"共%ld件商品,应付款%0.2f",num,price];
    
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:model.created_at.integerValue].st_localDate;
    
    self.timeLable.text = [NSString stringWithFormat:@"购买时间:%@",date.st_yyyyMMddhhmmssWithDate];
    
    self.orderLable.text = [NSString stringWithFormat:@"订单号:%@",model.order_sn];
    
}
- (void)setShopModel:(KLOrderModel *)shopModel{
    KLOrderModel *  model = shopModel;
    _model = model;
    
    [self.menuButton setTitle:[self defultShopTitle] forState:UIControlStateNormal];
    self.menuButton.hidden = !self.menuButton.currentTitle.length;
    
    NSInteger num = 0;
    CGFloat price = 0;
    for (KLOrderGoodModel * good in model.goodsorder) {
        num = num + good.goods_num.integerValue;
        price = price + good.goods_num.integerValue * good.goods_price.floatValue;
    }
    self.payLable.text = [NSString stringWithFormat:@"共%ld件商品,买家已付款%0.2f",num,price];
    
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:model.created_at.integerValue].st_localDate;
    
    self.timeLable.text = [NSString stringWithFormat:@"购买时间:%@",date.st_yyyyMMddhhmmssWithDate];
    
    self.orderLable.text = [NSString stringWithFormat:@"订单号:%@",model.order_sn];
    
}
@end

